package a09_贪心算法;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 * a14_根据身高重建队列复习2
 * </p>
 *
 * @author flyduck
 * @since 2025/2/24
 */
public class a14_根据身高重建队列复习2 {
    public static void main(String[] args) {
        reconstructQueue(new int[][]{{7,0},{4,4},{7,1},{5,0},{6,1},{5,2}});
    }
    //[[7,0],[4,4],[7,1],[5,0],[6,1],[5,2]]
    //[7,0][7,1][6,1][5,0][5,2][4,4]
    //
    public static int[][] reconstructQueue(int[][] people) {

        Arrays.sort(people,(item1, item2) -> {
            if (item1[0] == item2[0]) {
                return item1[1] - item2[1];
            } else {
                return item2[0] - item1[0];
            }
        });

        List<int[]> list = new ArrayList<>();
        for (int i = 0; i < people.length; i++) {
            list.add(people[i][1],people[i]);
        }

        return list.toArray(new int[list.size()][2]);
    }
}
